package cn.edu.zhku.citrusmonitor.qa.service;

import java.sql.SQLException;
import java.util.List;

import cn.edu.zhku.citrusmonitor.domain.TbAnswer;
import cn.edu.zhku.citrusmonitor.qa.dao.AnswerDao;
import cn.edu.zhku.citrusmonitor.qa.dao.AnswerDaoImpl;
import cn.edu.zhku.citrusmonitor.util.PageBean;

public class AnswerServiceImpl implements AnswerService {
	AnswerDao ad=new AnswerDaoImpl();
	
	@Override
	public void addA(TbAnswer answer) throws SQLException {
		ad.addA(answer);
	}

	@Override
	public int removeA(String answer) throws SQLException {
		return ad.removeA(answer);
	}

	@Override
	public int modifyA(TbAnswer answer) throws SQLException {
		return ad.modifyA(answer);
	}

	@Override
	public List<TbAnswer> findAByWord(String content) throws SQLException {
		return ad.findAByWord(content);
	}

	@Override
	public TbAnswer showA(String questionId) throws SQLException {
		
		return ad.showA(questionId);
	}

	@Override
	public String findExpertPasswordById(int expertId) throws SQLException {
		
		return ad.findExpertPasswordById(expertId);
	}

	@Override
	public PageBean<TbAnswer> showAll(int currentPage, int pageSize) throws SQLException {
		
		int count=ad.count(null);
		int totalPage=(int) Math.ceil(count/pageSize);
		
		List<TbAnswer> announcelist=ad.showAll(currentPage,pageSize);
				
		PageBean<TbAnswer> pb=new PageBean<TbAnswer>();
		pb.setCount(count);
		pb.setCurrentPage(currentPage);
		pb.setPageSize(pageSize);
		pb.setTotalPage(totalPage);
		pb.setList(announcelist);
		
		return pb;
	}

	@Override
	public int delAll(String[] ids) throws SQLException {
		
		return ad.delAll(ids);
	}
	

}
